package br.ufpe.cin.camid.core.agents;

import java.util.TimerTask;

import com.google.inject.TypeLiteral;
import com.google.inject.spi.TypeEncounter;
import com.google.inject.spi.TypeListener;

public class AgentListener implements TypeListener {

	private AgentConfig agentConfig;
	
	
	public AgentListener(AgentConfig agentConfig) {
		super();
		this.agentConfig = agentConfig;
	}



	@Override
	public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
		Class<?> definition = type.getRawType();
		if(TimerTask.class.isAssignableFrom(definition) && definition.isAnnotationPresent(Agent.class))
		{
			encounter.register( new AgentInjectionListener(agentConfig) );
		}
		
	}

}
